package com.platform.entity;

import java.io.Serializable;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.platform.util.SysConfigUtil;


/**
 * @author lipengjun
 * @email 939961241@qq.com
 * @date 2017-08-13 10:41:08
 */
/**
 * @author admin
 *
 */
public class GoodsEntity implements Serializable {
    private static final long serialVersionUID = 1L;

    private Integer parentId;
    //主键
    private Integer id;
    //商品类型Id
    private Integer categoryId;
    //商品序列号
    private String goodsSn;
    //名称
    private String name;
    //品牌Id  
    private Integer brandId;
    //关键字
    private String keywords;
    //简明介绍
    private String goodsBrief;
    //商品描述
    private String goodsDesc;
    //上架
    private Integer isOnSale;
    //排序
    private Integer sortOrder;
    //删除状态
    private Integer isDelete;
    //属性类别
    private Integer attributeCategory;
    //是否新商品
    private Integer isNew;
    //商品单位 作者
    private String goodsUnit;
    //商品主图  封面
    private String primaryPicUrl;

    /**
     * 首页顶部推荐
     */
    private Integer recommendation;
    
    //商品列表图
    private String listPicUrl;
    //展示价格
    private BigDecimal counterPrice;
    //零售原价
    private BigDecimal unitPrice;
    //会员价  7.5折
    private BigDecimal retailPrice;
    //代理价  5.8折
    private BigDecimal marketPrice;
    //特惠价  4.5折
    private BigDecimal appExclusivePrice;
    //附加价格
    private BigDecimal extraPrice;
    //销售量
    private Integer sellVolume;
    //浏览量
    private Integer readNum;
    
    //主sku　product_id
    private Integer primaryProductId;
    //推广描述
    private String promotionDesc;
    //推广标签
    private String promotionTag;
    //是否是APP专属
    private Integer isAppExclusive;
    //限购
    private Integer isLimited;
    //热销
    private Integer isHot;
    /**
     * 视频/音频类地址
     */
    private String audioUrl;
    
    /**
     * 测试 视频/音频类地址  未购买情况
     */
    private String testAudioUrl;
    
    /**
     * 前奏音屏
     */
    private String preludeAudioUrl;
    
    /**
     *  测试 视频/音频类描述  未购买情况
     */
    private String testContent;
    
    /**
     * 商品类型   0:文章  1:实物   2:虚拟类   3:音频  4:视频  99:打包类=>(音频-视频)
     */
    private Integer goodsType;
    
    //是否收藏
    private Integer collect = 0;
    
    //添加时间
    private Date addTime;
    //修改时间
    private Date updateTime;
    private UserEntity user;
    /**
     * 
     * 商品库存
     * 
     **/
    private Integer goodsNumber;
    /**
     * 用户ID
     */
    private Long createUserId;
    /**
     * 用户ID
     */
    private Long createUserDeptId;
    /**
     * 用户ID
     */
    private Long updateUserId;
    
    private String subPicUrl;
    private String subPicUrlb;

    private String contentUrl;
    private String testContentUrl;
    /**
     * 翻译用字段
     */
    //商品类型
    private String categoryName;
    //属性类别
    private String attributeCategoryName;
    //品牌
    private String brandName;
    
    private String typeName;
    
    private boolean buyed = true;
    List<GoodsAttributeEntity> attributeEntityList = new ArrayList<>();
    //商品轮播图
    List<GoodsGalleryEntity> goodsImgList = new ArrayList<>();
    
    /**
     * 折扣
     */
    private String discount;
    
    public Integer getCollect() {
    	if(collect == null)
    		return 0;
		return collect;
	}

	public void setCollect(Integer collect) {
		this.collect = collect;
	}

	public Long getCreateUserDeptId() {
        return createUserDeptId;
    }

    public void setCreateUserDeptId(Long createUserDeptId) {
        this.createUserDeptId = createUserDeptId;
    }

    public List<GoodsGalleryEntity> getGoodsImgList() {
        return goodsImgList;
    }

    public void setGoodsImgList(List<GoodsGalleryEntity> goodsImgList) {
        this.goodsImgList = goodsImgList;
    }

    public String getBrandName() {
        return brandName;
    }

    public void setBrandName(String brandName) {
        this.brandName = brandName;
    }

    public String getAttributeCategoryName() {
        return attributeCategoryName;
    }

    public void setAttributeCategoryName(String attributeCategoryName) {
        this.attributeCategoryName = attributeCategoryName;
    }

    public String getCategoryName() {
        return categoryName;
    }

    public void setCategoryName(String categoryName) {
        this.categoryName = categoryName;
    }

    /**
     * 设置：主键
     */
    public void setId(Integer id) {
        this.id = id;
    }

    /**
     * 获取：主键
     */
    public Integer getId() {
        return id;
    }

    /**
     * 设置：商品类型Id
     */
    public void setCategoryId(Integer categoryId) {
        this.categoryId = categoryId;
    }

    /**
     * 获取：商品类型Id
     */
    public Integer getCategoryId() {
        return categoryId;
    }

    /**
     * 设置：商品序列号
     */
    public void setGoodsSn(String goodsSn) {
        this.goodsSn = goodsSn;
    }

    /**
     * 获取：商品序列号
     */
    public String getGoodsSn() {
        return goodsSn;
    }

    /**
     * 设置：名称
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * 获取：名称
     */
    public String getName() {
        return name;
    }

    /**
     * 设置：品牌Id
     */
    public void setBrandId(Integer brandId) {
        this.brandId = brandId;
    }

    /**
     * 获取：品牌Id
     */
    public Integer getBrandId() {
        return brandId;
    }

    /**
     * 设置：商品序列号
     */
    public void setGoodsNumber(Integer goodsNumber) {
        this.goodsNumber = goodsNumber;
    }

    /**
     * 获取：商品序列号
     */
    public Integer getGoodsNumber() {
        return goodsNumber;
    }

    /**
     * 设置：关键字
     */
    public void setKeywords(String keywords) {
        this.keywords = keywords;
    }

    /**
     * 获取：关键字
     */
    public String getKeywords() {
        return keywords;
    }

    /**
     * 设置：简明介绍
     */
    public void setGoodsBrief(String goodsBrief) {
        this.goodsBrief = goodsBrief;
    }

    /**
     * 获取：简明介绍
     */
    public String getGoodsBrief() {
        return goodsBrief;
    }

    /**
     * 设置：商品描述
     */
    public void setGoodsDesc(String goodsDesc) {
        this.goodsDesc = goodsDesc;
    }

    /**
     * 获取：商品描述
     */
    public String getGoodsDesc() {
        return goodsDesc;
    }

    /**
     * 设置：上架
     */
    public void setIsOnSale(Integer isOnSale) {
        this.isOnSale = isOnSale;
    }

    /**
     * 获取：上架
     */
    public Integer getIsOnSale() {
        return isOnSale;
    }

    /**
     * 设置：添加时间
     */
    public void setAddTime(Date addTime) {
        this.addTime = addTime;
    }

    /**
     * 获取：添加时间
     */
    public Date getAddTime() {
        return addTime;
    }

    /**
     * 设置：排序
     */
    public void setSortOrder(Integer sortOrder) {
        this.sortOrder = sortOrder;
    }

    /**
     * 获取：排序
     */
    public Integer getSortOrder() {
        return sortOrder;
    }

    /**
     * 设置：删除状态
     */
    public void setIsDelete(Integer isDelete) {
        this.isDelete = isDelete;
    }

    /**
     * 获取：删除状态
     */
    public Integer getIsDelete() {
        return isDelete;
    }

    /**
     * 设置：属性类别
     */
    public void setAttributeCategory(Integer attributeCategory) {
        this.attributeCategory = attributeCategory;
    }

    /**
     * 获取：属性类别
     */
    public Integer getAttributeCategory() {
        return attributeCategory;
    }

    /**
     * 设置：专柜价格
     */
    public void setCounterPrice(BigDecimal counterPrice) {
        this.counterPrice = counterPrice;
    }

    /**
     * 获取：专柜价格
     */
    public BigDecimal getCounterPrice() {
        return counterPrice;
    }

    /**
     * 设置：附加价格
     */
    public void setExtraPrice(BigDecimal extraPrice) {
        this.extraPrice = extraPrice;
    }

    /**
     * 获取：附加价格
     */
    public BigDecimal getExtraPrice() {
        return extraPrice;
    }

    /**
     * 设置：是否新商品
     */
    public void setIsNew(Integer isNew) {
        this.isNew = isNew;
    }

    /**
     * 获取：是否新商品
     */
    public Integer getIsNew() {
        return isNew;
    }

    /**
     * 设置：商品单位
     */
    public void setGoodsUnit(String goodsUnit) {
        this.goodsUnit = goodsUnit;
    }

    /**
     * 获取：商品单位
     */
    public String getGoodsUnit() {
        return goodsUnit;
    }

    /**
     * 设置：商品主图
     */
    public void setPrimaryPicUrl(String primaryPicUrl) {
        this.primaryPicUrl = primaryPicUrl;
    }

    /**
     * 获取：商品主图
     */
    public String getPrimaryPicUrl() {
        return primaryPicUrl;
    }

    /**
     * 设置：商品列表图
     */
    public void setListPicUrl(String listPicUrl) {
        this.listPicUrl = listPicUrl;
    }

    /**
     * 获取：商品列表图
     */
    public String getListPicUrl() {
        return listPicUrl;
    }

    /**
     * 设置：会员价  7.5折
     */
    public void setRetailPrice(BigDecimal retailPrice) {
        this.retailPrice = retailPrice;
    }

    /**
     * 获取：会员价  7.5折
     */
    public BigDecimal getRetailPrice() {
        return retailPrice;
    }

    /**
     * 设置：销售量
     */
    public void setSellVolume(Integer sellVolume) {
        this.sellVolume = sellVolume;
    }

    /**
     * 获取：销售量
     */
    public Integer getSellVolume() {
        return sellVolume;
    }

    /**
     * 设置：主sku　product_id
     */
    public void setPrimaryProductId(Integer primaryProductId) {
        this.primaryProductId = primaryProductId;
    }

    /**
     * 获取：主sku　product_id
     */
    public Integer getPrimaryProductId() {
        return primaryProductId;
    }

    /**
     * 设置：零售原价
     */
    public void setUnitPrice(BigDecimal unitPrice) {
        this.unitPrice = unitPrice;
    }

    /**
     * 获取：零售原价
     */
    public BigDecimal getUnitPrice() {
    	if(unitPrice == null)
    		return BigDecimal.valueOf(0);
        return unitPrice;
    }

    /**
     * 设置：推广描述
     */
    public void setPromotionDesc(String promotionDesc) {
        this.promotionDesc = promotionDesc;
    }

    /**
     * 获取：推广描述
     */
    public String getPromotionDesc() {
        return promotionDesc;
    }

    /**
     * 设置：推广标签
     */
    public void setPromotionTag(String promotionTag) {
        this.promotionTag = promotionTag;
    }

    /**
     * 获取：推广标签
     */
    public String getPromotionTag() {
        return promotionTag;
    }

    /**
     * 设置：特惠价  4.5折
     */
    public void setAppExclusivePrice(BigDecimal appExclusivePrice) {
        this.appExclusivePrice = appExclusivePrice;
    }

    /**
     * 获取：特惠价  4.5折
     */
    public BigDecimal getAppExclusivePrice() {
        return appExclusivePrice;
    }

    /**
     * 设置：是否是APP专属
     */
    public void setIsAppExclusive(Integer isAppExclusive) {
        this.isAppExclusive = isAppExclusive;
    }

    /**
     * 获取：是否是APP专属
     */
    public Integer getIsAppExclusive() {
        return isAppExclusive;
    }

    /**
     * 设置：限购
     */
    public void setIsLimited(Integer isLimited) {
        this.isLimited = isLimited;
    }

    /**
     * 获取：限购
     */
    public Integer getIsLimited() {
        return isLimited;
    }

    /**
     * 设置：热销
     */
    public void setIsHot(Integer isHot) {
        this.isHot = isHot;
    }

    /**
     * 获取：热销
     */
    public Integer getIsHot() {
        return isHot;
    }

    /**
     * 代理价  5.8折
     * @return
     */
    public BigDecimal getMarketPrice() {
        return marketPrice;
    }

    /**
     * 代理价  5.8折
     * @param marketPrice
     */
    public void setMarketPrice(BigDecimal marketPrice) {
        this.marketPrice = marketPrice;
    }

    public List<GoodsAttributeEntity> getAttributeEntityList() {
        return attributeEntityList;
    }

    public void setAttributeEntityList(List<GoodsAttributeEntity> attributeEntityList) {
        this.attributeEntityList = attributeEntityList;
    }

    public Long getCreateUserId() {
        return createUserId;
    }

    public void setCreateUserId(Long createUserId) {
        this.createUserId = createUserId;
    }

    public Long getUpdateUserId() {
        return updateUserId;
    }

    public void setUpdateUserId(Long updateUserId) {
        this.updateUserId = updateUserId;
    }

    public Date getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }

	public Integer getRecommendation() {
		if(recommendation == null)
			recommendation = 0;
		return recommendation;
	}

	public void setRecommendation(Integer recommendation) {
		this.recommendation = recommendation;
	}
    
	public String getSubPicUrl() {
		return subPicUrl;
	}

	public void setSubPicUrl(String subPicUrl) {
		this.subPicUrl = subPicUrl;
	}

	public String getSubPicUrlb() {
		return subPicUrlb;
	}

	public void setSubPicUrlb(String subPicUrlb) {
		this.subPicUrlb = subPicUrlb;
	}

	public String[] getKeywordArray() {
		if(keywords == null)
			return null;
		return keywords.split(" ");
	}
	public String getAudioUrl() {
		return audioUrl;
	}

	public void setAudioUrl(String audioUrl) {
		this.audioUrl = audioUrl;
	}

	public String getTestAudioUrl() {
		return testAudioUrl;
	}

	public void setTestAudioUrl(String testAudioUrl) {
		this.testAudioUrl = testAudioUrl;
	}

	/**
	 * 商品类型   0:文章  1:实物   2:虚拟类   3:音频  4:视频  99:打包类
	 * @return
	 */
	public Integer getGoodsType() {
		return goodsType;
	}

	public void setGoodsType(Integer goodsType) {
		this.goodsType = goodsType;
	}

	public String getTestContent() {
		return testContent;
	}

	public void setTestContent(String testContent) {
		this.testContent = testContent;
	}
	
//    //展示价格
//    //零售原价
//    //会员价  7.5折
//    //代理价  5.8折
//    //特惠价  4.5折
	//当前用户售价
	public BigDecimal getSalePrice() {
        if(user == null) {
        	return unitPrice;
        }else {
        	switch(user.getUserLevelId()) {
	        	case 0:
	        			return unitPrice;
	        	case 1:
	        			return retailPrice;
	        	case 2:
	        			return marketPrice;
	        	case 3:
	        			return appExclusivePrice;
        		default:
        			return unitPrice;
        	}
        }
	}
	
	public String getDiscount() {
		Float discount;
        if(user == null) {
        	discount = unitPrice.floatValue()/counterPrice.floatValue();
        }else {
        	switch(user.getUserLevelId()) {
	        	case 0:
	        		discount = unitPrice.floatValue()/counterPrice.floatValue();
	        	case 1:
	        		discount = retailPrice.floatValue()/counterPrice.floatValue();
	        	case 2:
	        		discount = marketPrice.floatValue()/counterPrice.floatValue();
	        	case 3:
	        		discount = appExclusivePrice.floatValue()/counterPrice.floatValue();
        		default:
        			discount = unitPrice.floatValue()/counterPrice.floatValue();
        	}
        }
        
        DecimalFormat decimalFormat=new DecimalFormat(".0");//构造方法的字符格式这里如果小数不足2位,会以0补足.
        return decimalFormat.format(discount);//format 返回的是字符串
	}

	public UserEntity getUser() {
		return user;
	}

	public void setUser(UserEntity user) {
		this.user = user;
	}

	public BigDecimal getSalePrice(UserEntity user) {
        if(user == null) {
        	return unitPrice;
        }else {
        	switch(user.getUserLevelId()) {
	        	case 0:
	        			return unitPrice;
	        	case 1:
	        			return retailPrice;
	        	case 2:
	        			return marketPrice;
	        	case 3:
	        			return appExclusivePrice;
        		default:
        			return unitPrice;
        	}
        }
	}

	public boolean getBuyed() {
		return buyed;
	}

	public void setBuyed(boolean buyed) {
		if(!buyed) {
			this.setGoodsDesc(null);
			this.setAudioUrl(null);
		}
		this.buyed = buyed;
	}

	public Integer getParentId() {
		if(parentId == null)
			parentId = 0;
		return parentId;
	}

	public void setParentId(Integer parentId) {
		this.parentId = parentId;
	}

	public Integer getReadNum() {
		return readNum;
	}

	public void setReadNum(Integer readNum) {
		this.readNum = readNum;
	}

	/**
	 * 是否权限类，只需购买一份
	 * @return
	 */
	public boolean isPrivilege() {
		if(goodsType == null)
			return false;
		if(goodsType == 0 || goodsType == 3 || goodsType == 4) {
			return true;
		}
		return false;
	}

	public String getPreludeAudioUrl() {
		return preludeAudioUrl;
	}

	public void setPreludeAudioUrl(String preludeAudioUrl) {
		this.preludeAudioUrl = preludeAudioUrl;
	}

	public String getContentUrl() {
		return contentUrl;
	}

	public void setContentUrl(String contentUrl) {
		this.contentUrl = contentUrl;
	}

	public String getTestContentUrl() {
		return testContentUrl;
	}

	public void setTestContentUrl(String testContentUrl) {
		this.testContentUrl = testContentUrl;
	}

	public String getTypeName() {
		if(goodsType == null || SysConfigUtil.getConfigsByTypeKey("goodsType",goodsType.toString(),false) == null) {
			return "未知_" + goodsType;
		}
		return SysConfigUtil.getConfigsByTypeKey("goodsType",goodsType.toString(),false);
	}
	
}
